package com.szl.yeb.controller;


import com.szl.yeb.common.constant.MsgConstant;
import com.szl.yeb.dto.MenuDto;
import com.szl.yeb.entity.Menu;
import com.szl.yeb.common.R;
import com.szl.yeb.common.PageResult;
import com.szl.yeb.service.MenuService;
import com.szl.yeb.utils.ResponseProcessor;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.Serializable;

/**
 * (Menu)表控制层
 *
 * @author szl
 * @since 2022-08-24 16:21:26
 */
@Api(tags = "菜单接口(MenuController)")
@RestController
@RequestMapping("/system/cfg")
public class MenuController {

    @Autowired
    private MenuService menuService;

    @GetMapping("/menu")
    @ApiOperation("根据用户id查询菜单列表")
    public R<Object> getMenusByAdminId() {
        return menuService.getMenusByAdminId();
    }

    @ApiOperation("查询所有菜单树")
    @GetMapping("/menuTree")
    public R<Object> getMenusWithChildrenWithFullData() {
        return R.obj(menuService.getMenusWithChildrenWithFullData());
    }

    @ApiOperation("添加菜单")
    @PostMapping("/menu")
    public R<Object> addMenu(@RequestBody Menu menu) {
        return ResponseProcessor.getResWithMsg(menuService.addMenu(menu), MsgConstant.ADD);
    }

    @ApiOperation("修改菜单")
    @PutMapping("/menu")
    public R<Object> updateMenu(@RequestBody MenuDto menudto) {
        return ResponseProcessor.getResWithMsg(menuService.updateMenu(menudto), MsgConstant.UPDATE);
    }

    @ApiOperation("删除菜单")
    @DeleteMapping("/menu")
    public R<Object> deleteMenu(Integer id,Integer parentId) {
        return ResponseProcessor.getResWithMsg(menuService.deleteMenu(id,parentId), MsgConstant.DELETE);
    }

}

